// pages/collect/index.js
Page({
  data: {
    tabs: [  //Tabs组件的数据
      {
        id:0,
        value:'商品收藏',
        isActive:true
      },
      {
        id:1,
        value:'品牌收藏',
        isActive:false
      },
      {
        id:2,
        value:'店铺收藏',
        isActive:false
      },
      {
        id:3,
        value:'浏览足迹',
        isActive:false
      }
    ],
    collect: [],  //收藏商品数组
  },
  
  onShow(){
    //1 从缓存中取出收藏商品数组
    const collect = wx.getStorageSync('collect') || []

    //2 保存到data中
    this.setData({
      collect
    })

  },

  //点击 tabs栏 选项
  handleTabsItemChange(e){
    //console.log(e)

    //1.获取被点击的标题索引
    const {index} = e.detail
    //console.log(index)

   //2.修改源数组
   let {tabs} = this.data
   tabs.forEach((v,i) => i===index?v.isActive=true:v.isActive=false)
   
   //3.赋值到data中
   this.setData({tabs})
  },

})

